// TestCpp.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <WinSock2.h>
#include <cpp_redis\future_client.hpp>
#include <iostream>

#pragma comment(lib,"ws2_32.lib")

int main()
{
#ifdef _WIN32  
	//! Windows netword DLL init  
	WORD version = MAKEWORD(2, 2);
	WSADATA data;

	if (WSAStartup(version, &data) != 0) {
		std::cout << "WSAStartup() failure" << std::endl;
		return -1;
	}
#endif /* _WIN32 */  

	cpp_redis::future_client client;

	client.connect("127.0.0.1");

	if (!client.is_connected())
		return -1;

	time_t t = time(NULL);
	tm* local = localtime(&t);
	char buf[50] = { 0 };
	strftime(buf, 64, "%Y-%m-%d %H:%M:%S", local);
	std::vector<std::string> vals;
	vals.push_back(buf);
	auto ret = client.rpush("testlist", vals);
	client.sync_commit();
	//std::cout << ret.get() << std::endl;
	int64_t nCount = ret.get().as_integer();
	std::cout << nCount << std::endl;

	ret = client.llen("testlist");
	client.sync_commit();
	//std::cout << ret.get() << std::endl;
	nCount = ret.get().as_integer();
	std::cout << nCount << std::endl;

	ret = client.lrange("testlist", 0, nCount - 1);
	client.sync_commit();
	//std::cout << ret.get() << std::endl;
	std::vector<cpp_redis::reply> msgs = ret.get().as_array();
	std::string msg;
	for (std::vector<cpp_redis::reply>::iterator it = msgs.begin(); it != msgs.end(); it++)
	{
		msg = it->as_string();
		std::cout << msg << std::endl;
	}

	std::getchar();

#ifdef _WIN32  
	WSACleanup();
#endif /* _WIN32 */  

	return 0;
}
